package skins {

   import flash.display.*;
   import flash.filters.DropShadowFilter;
   import flash.geom.*;
   import flash.utils.*;
   
   import mx.core.EdgeMetrics;
   import mx.skins.RectangularBorder;
   import mx.utils.GraphicsUtil;
   import mx.controls.Alert;

   public class CustomBorder extends RectangularBorder{
      public function CustomBorder() {
         super();
      }

      override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
         
         
         super.updateDisplayList(unscaledWidth, unscaledHeight);
            
            var backgroundColor:int = getStyle("backgroundColor");
            var backgroundAlpha:Number = getStyle("backgroundAlpha");
            var borderColor:Number = getStyle("borderColor");
            
            var gradientStyle:String = this.getStyle("gradientStyle");
            var hasdropshadow:String = this.getStyle("hasdropshadow");
            
            var g:Graphics = graphics;

            var cn:Number = this.getStyle("cornerRadius");
            var crtl:Number = this.getStyle("cornerRadiusTopLeft") > 0 ? this.getStyle("cornerRadiusTopLeft") : cn;
            var crtr:Number = this.getStyle("cornerRadiusTopRight") > 0 ? this.getStyle("cornerRadiusTopRight") : cn;
            var crbl:Number = this.getStyle("cornerRadiusBottomLeft") > 0 ? this.getStyle("cornerRadiusBottomLeft") : cn;
            var crbr:Number = this.getStyle("cornerRadiusBottomRight") > 0 ? this.getStyle("cornerRadiusBottomRight") : cn;
            var gradFrom:Number = this.getStyle("gradientFrom");
            var gradTo:Number = this.getStyle("gradientTo");
            
            var b:EdgeMetrics = borderMetrics;
            var w:Number = unscaledWidth - b.left - b.right;
            var h:Number = unscaledHeight - b.top - b.bottom;
            var m:Matrix;
            if(gradientStyle == 'horizontal')
            	m = horizontalGradientMatrix(0, 0, w, h);
            else
            	m = verticalGradientMatrix(0, 0, w, h);
            
            

            g.clear();
            g.beginGradientFill("linear", [gradFrom, gradTo], [1, 1], [0, 255], m);
            g.lineStyle(1,borderColor,0,true,LineScaleMode.NORMAL,CapsStyle.SQUARE,JointStyle.BEVEL);
            GraphicsUtil.drawRoundRectComplex(g, b.left, b.top, w, h, crtl, crtr, crbl, crbr);
            
            g.endFill();
            
            if(hasdropshadow == 'true'){
            	var dropshadowalpha:Number = 1;
            	if(this.getStyle("dropshadowalpha"))
            		dropshadowalpha = this.getStyle("dropshadowalpha");
            	
            	this.filters = [new DropShadowFilter(4, 45,0x000000, dropshadowalpha)];
            }
            
            this.alpha = backgroundAlpha;
            
            
            
           	
      }
   }
}